qui(
    function (require, exports, module) {
        Director.Model = (function () {
            var streamTypeConfig = {
                HIGH_DEFINITION: "高清",
                RESOLUTION_720P: "超清720P",
                RESOLUTION_1080P: "1080P"
            }
            var timerModel = {
                countTime: $("span[name=countTimerHint]"),
                dayLabel: $("span[name=span_time_day_label]"),
                day: $("span[name=span_time_day]"),
                hour: $("span[name=span_time_hour]"),
                minute: $("span[name=span_time_minute]"),
                second: $("span[name=span_time_second]"),
                playStatusLabel: $("span[name=span_paly_status_label]"),
                cdId: -1

            };

            var detailModel = {
                name: $("span[name=span_program_name]"),
                qipuId: $("span[name=span_program_id]"),
                delay: $("span[name=span_delay]"),
                outputUrl: $("span[name=span_output_url]"),
                outputStreamType: $("span[name=span_output_stream_type]"),
                startTime: $("span[name=span_startTime]"),
                endTime: $("span[name=span_endTime]")
            }

            function updateTimeModel(darArr) {
                timerModel.dayLabel.hide();
                timerModel.day.hide();
                switch (darArr.length) {
                    case 4:
                        timerModel.day.html(darArr[3] < 10 ? "0" + darArr[3] : darArr[3]);
                        timerModel.dayLabel.show();
                        timerModel.day.show();
                    case 3:
                        timerModel.hour.html(darArr[2] < 10 ? "0" + darArr[2] : darArr[2]);
                    case 2:
                        timerModel.minute.html(darArr[1] < 10 ? "0" + darArr[1] : darArr[1]);
                    case 1:
                        timerModel.second.html(darArr[0] < 10 ? "0" + darArr[0] : darArr[0]);
                        break;
                }
                timerModel.second.addClass("time-brown");
                timerModel.day.addClass("time-brown");
                timerModel.hour.addClass("time-brown");
                timerModel.minute.addClass("time-brown");
            }

            function updateRunningMode() {
                timerModel.countTime.html("正在直播");
                timerModel.countTime.css({color:"#136eb4"});
                timerModel.playStatusLabel.html("").removeClass("play_status_default").addClass("play_status_running");
                timerModel.day.removeClass("time-brown").addClass("time-green");
                timerModel.hour.removeClass("time-brown").addClass("time-green");
                timerModel.minute.removeClass("time-brown").addClass("time-green");
                timerModel.second.removeClass("time-brown").addClass("time-green");
            }
            function updateEndMode(){
               // timerModel.countTime.html("直播结束");
                timerModel.playStatusLabel.html("直播结束").removeClass("play_status_default").removeClass("play_status_running").addClass("play_status_end");
                $("#running_zone").hide();
                $("#end_zone").show();
            }

            function initDetail(entity) {
                detailModel.name.html(entity.programName);
                detailModel.qipuId.html(entity.programQipuId);
                detailModel.delay.html(entity.delay);
                if(entity.outputUrl == null || entity.outputUrl.length < 10){
                    detailModel.outputUrl.html("<p style='color:red'>输出地址为空，请去设置</p>")
                }else{
                    detailModel.outputUrl.html( Director.Util.resizeTextWidth( entity.outputUrl,240));
                }
                detailModel.outputStreamType.html(streamTypeConfig[entity.outputStreamType]);
                var timeArr = entity.startPlayTime.split(/ |:/)
                detailModel.startTime.html('<span style="font-size: 18px">' + timeArr[1] + ":" + timeArr[2] + '</span> (' + timeArr[0] + ')');
                timeArr = entity.stopPlayTime.split(/ |:/)
                detailModel.endTime.html('<span style="font-size: 18px">' + timeArr[1] + ":" + timeArr[2] + '</span> (' + timeArr[0] + ')');
            }

            function initCountDownTimer(entity) {
                timerModel.cdId = setInterval(function () {
                    Director.Util.setTimer(entity.startPlayTime,entity.stopPlayTime)
                }, 500);
            }

            function stopTimer(){
                if(timerModel.cdId > 0){
                    clearInterval(timerModel.cdId);
                    timerModel.cdId = -1;
                }
            }

            function getTimerModel(){
                return timerModel;
            }

            return {
                updateTimeModel: updateTimeModel,
                updateRunningMode: updateRunningMode,
                updateEndMode: updateEndMode,
                initDetail: initDetail,
                initCountDownTimer: initCountDownTimer,
                stopTimer : stopTimer,
                getTimerModel:getTimerModel
            }
        })()
    }
);